<!DOCTYPE html>
<html lang="">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>User Register</title>

		<!-- Bootstrap CSS -->
		<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
		<!-- Alertdialog -->
		<link rel="stylesheet" type="text/css" href="/css/ui-dialog.css">
		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
			<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
			<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
		<![endif]-->
	</head>
	<body>
		
		<div class="container text-center">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">如果只是遇见，不能停留，不如不遇见。</h3>
				</div>
				<div class="panel-body">
					If we can only encounter each other rather than stay with each other,then I wish we had never encountered. 
				</div>
			</div>
			<div>
				<div class="panel panel-info text-center">
					<div class="panel-heading">
						<h1 class="panel-title">Blog</h1>
						<h5 class='text-success'>My Frist Blog</h5>
					</div>
					<div class="panel-body">
						<form action="/user/register" method="POST" role="form">
							<legend>User Register</legend>
						
							<div class="form-group">
								<label for="name">User Name</label>
								<input type="text" class="form-control" id="name" name="userName" placeholder="Input User Name">
								<div id="name_message"></div>
							</div>

							<div class="form-group">
								<label for="pwd">User Password</label>
								<input type="password" class="form-control" id="pwd" name="userPwd" placeholder="Input User Password">
							</div>

							<div class="form-group">
								<label for="repwd">User Repeat Password</label>
								<input type="password" class="form-control" id="repwd" name="userRePwd" placeholder="Input User Repeat Password">
							</div>
							
							<div class="form-group">
								<label for="userGender">User Gender</label>
								<select name="userGender" id="userGender" class="form-control" required="required">
									<option value="未知">Please Choose your Gender</option>
									<option value="男">-- 男 --</option>
									<option value="女">-- 女 --</option>
								</select>
							</div>

							<div class="form-group">
								<label for='introduction'>User Introduction</label>
								<textarea name="userIntroduction" id="introduction" class="form-control" rows="3" placeholder="input your Introduction" required="required"></textarea>
							</div>
							<button type="submit" id="btn_submit" class="btn btn-primary btn-block">Submit</button>
						</form>
					</div>
					<%- include('../footer')%>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="/js/jquery-1.10.2.js"></script>
		<!-- Bootstrap JavaScript -->
		<script type="text/javascript" src="/js/bootstrap.min.js"></script>
		<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
		<!-- dialog-min.js -->
		<script src="/js/dialog-min.js" type="text/javascript" charset="utf-8" async defer></script>
		<!-- dialog-plus-min.js -->
		<script src="/js/dialog-plus-min.js" type="text/javascript" charset="utf-8" async defer></script>
		<script src="/js/canvas-particle.js"></script>
		<script type="text/javascript">
			window.onload = function(){
		    	//配置
			    var config = {
			        vx: 4,//点x轴速度,正为右，负为左
			        vy:  4,//点y轴速度
			        height: 2,//点高宽，其实为正方形，所以不宜太大
			        width: 2,
			        count: 100,//点个数
			        color: "121, 162, 185",//点颜色
			        stroke: "130,255,255",//线条颜色
			        dist: 6000,//点吸附距离
			        e_dist: 20000,//鼠标吸附加速距离
			        max_conn: 10//点到点最大连接数
			    }
			    //调用
			    CanvasParticle(config);
			}
		</script>
		<script type='text/javascript'>
			//验证表单
			$('#btn_submit').on('click',function () {
				if($('#name').val() == null || $('#name').val() == ''){
					$('#name').focus();
					return false;
				}

				if($('#pwd').val() == null || $('#pwd').val() == ''){
					$('#pwd').focus();
					return false;
				}

				if($('#pwd').val().length < 6){
					dialog({
						title:'Error',
						content:"password's lenght must > 6"
					}).show(document.getElementById('pwd'));
					$('#pwd').focus();
					return false;
				}

				if($('#repwd').val() == null || $('#repwd').val() == ''){
					$('#repwd').focus();
					return false;
				}

				if($('#repwd').val() != $('#pwd').val()){
					$('#pwd').val('');
					$('#repwd').val('');
					$('#pwd').focus();
					return false;
				}

				if($('#introduction').val() == null || $('#introduction').val() == ''){
					$('#introduction').focus();
					return false;
				}
			});

			$('#name').on('input', function() {
				//检查name是否可用
				$.post('/user/check', {name: $('#name').val()}, function(data, textStatus, xhr) {
					var d = null;
					if(!data.status){
						$('#btn_submit').attr('disabled',true);
						d = dialog({
							title:'错误',
							content:data.message
						}).show(document.getElementById('name'));
						$('#name').focus();
						setTimeout(function(){
							d.close().remove();
						},2000);
					}else{
						$('#btn_submit').attr('disabled', false);
					}
				});
			});
		</script>
	</body>
</html>